package com.lifang.test6;

import com.lifang.framework.context.support.AnnotationConfigApplicationContext;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
public class TestApp {

    @Resource(name = "userServiceImplA")
    private static UserService userService;

    /**
     * 多例 + aop + ioc + 循环依赖 + 基本生命周期，Aware感知，初始化 销毁方法
     * <p>
     * 广播，观察者
     * ApplicationRefreshEvent         容器刷新完成广播
     * ApplicationContextClosedEvent   容器关闭广播
     * CustomEventListener             自定义广播
     */
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(TestApp.class);
        UserService userService = (UserService) applicationContext.getBean("userServiceImplA");
        System.out.println(userService.sayHelloReturn("张三"));
        Map<String, UserService> userServiceMap = applicationContext.getBeansOfType(UserService.class);
        for (Map.Entry<String, UserService> entry : userServiceMap.entrySet()) {
            log.info("beanName={} bean={} beanClass={}", entry.getKey(), entry.getValue(), entry.getValue().getClass());
        }
        Map<String, UserService> userServiceMap1 = applicationContext.getBeansOfType(UserService.class);
        for (Map.Entry<String, UserService> entry : userServiceMap1.entrySet()) {
            log.info("beanName={} bean={} beanClass={}", entry.getKey(), entry.getValue(), entry.getValue().getClass());
            String aReturn = entry.getValue().sayHelloReturn("张三");
            log.info(aReturn);
        }
    }

}
